package com.yanqu.road.server.cmd.activity.shuihu;

import com.yanqu.road.entity.activity.shuihu.config.ShuiHuConfig;
import com.yanqu.road.pb.activity.ShuiHuActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.shuihu.ShuiHuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SHUIHU_ACTIVITY_GET_BOX_DATA, desc = "获取奖池数据")
public class GetShuiHuBoxDataCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ShuiHuConfig shuiHuConfig = ShuiHuMgr.getShuiHuConfig();

        if (shuiHuConfig == null || !ActivityMgr.activityInShowTime(shuiHuConfig.getActivityInfo())) {
            ret = GameErrorCode.E_SHUIHU_ACTIVITY_NO_OPEN;
            return;
        }

        ShuiHuActivityProto.CrossGetShuiHuBoxDataReqMsg.Builder builder = ShuiHuActivityProto.CrossGetShuiHuBoxDataReqMsg.newBuilder();
        builder.setActivityId(shuiHuConfig.getActivityId());
        builder.setServerId(player.getUserInfo().getOriginalServerId());
        builder.setUserId(player.getUserId());
        player.sendPacket(CrossProtocol.C2_SHUIHU_ACTIVITY_GET_BOX_DATA, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShuiHuActivityProto.GetShuiHuBoxDataRespMsg.Builder builder = ShuiHuActivityProto.GetShuiHuBoxDataRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SHUIHU_ACTIVITY_GET_BOX_DATA, builder);
        }
    }
}
